﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using EC_DataBase;

namespace EasyCheque.User
{
    public partial class AccountInfo : System.Web.UI.Page
    {
        private void fillTextBoxes_ByCurrentAccountID()
        {
            // 将那个选中的ID的信息列出来。
            string currentAccountID = DropDownList_ACCOUNT_ID.SelectedValue.ToString();
            Account_Info infoHere = OperateDB.Get_Account_Info(currentAccountID);

            if (infoHere == null)
            {
                return;
            }

            TextBox_ACC_TYPE.Text = infoHere.type;
            TextBox_PERSON.Text = infoHere.person;
            TextBox_BANK.Text = infoHere.bank;
            TextBox_REGTIME.Text = infoHere.reg_time;
            TextBox_MONEY.Text = infoHere.money;
            double actualUseable = Convert.ToDouble(infoHere.money) - Convert.ToDouble(infoHere.useable);
            TextBox_USEABLE.Text = actualUseable.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }

            Panel_Calendar.Style["display"] = "none";
            Panel_Calendar.Style["position"] = "absolute";

            // 先读入所有的AccountID。
            string[] allAccountIDs = OperateDB.Get_All_Acc_IDs(Convert.ToInt32(Session["uid"]));
            foreach (string accountID in allAccountIDs)
            {
                DropDownList_ACCOUNT_ID.Items.Add(accountID);
            }

            fillTextBoxes_ByCurrentAccountID();
        }

        protected void Calendar_InPanel_SelectionChanged(object sender, EventArgs e)
        {
            TextBox_REGTIME.Text = Calendar_InPanel.SelectedDate.ToString("yyyy-MM-dd");
        }

        protected void Calendar_InPanel_VisibleMonthChanged(Object sender, MonthChangedEventArgs e)
        {

            Panel_Calendar.Style["display"] = "";
        }

        protected void DropDownList_ACCOUNT_ID_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            fillTextBoxes_ByCurrentAccountID();
        }
    }
}
